import os, platform, sys
from wx.tools.dbg import Logger

''' check arguments'''
print sys.argv

VERSION = '2.1 E';
VNUM = (2,0,0)
TYPE = 1; # 0:B 1:E

ENABLEDEBUG = False
ENABLEDEBUG = ('-debug' in sys.argv or '-d' in sys.argv)

reset_settings = ('-reset' in sys.argv or '-r' in sys.argv)
print "Debug: " + str(ENABLEDEBUG)
print "Reset: " + str(reset_settings)


SETTINGS_DIR = ""

if platform.system() == "Windows":
            SETTINGS_DIR = os.path.join(os.getenv("appdata"),"MailDrop")
elif platform.system() == "Linux":
            SETTINGS_DIR = os.path.join(os.getenv("HOME"),".maildrop")
elif platform.system() == "Darwin":
            SETTINGS_DIR = os.path.join(os.getenv("HOME"),".maildrop")


DEBUGSTREAM = None
if ENABLEDEBUG:
    debugfile = os.path.join(SETTINGS_DIR,"debug.txt")
    if not os.path.exists(os.path.split(debugfile)[0]):
        os.mkdir(os.path.split(debugfile)[0])
    DEBUGSTREAM = open(debugfile, 'w+')

debug = Logger('maildroplibs')
debug.SetStream(DEBUGSTREAM)
debug(enable = ENABLEDEBUG)

import socks

PROXY_TYPE_SOCKS4 = socks.PROXY_TYPE_SOCKS4
PROXY_TYPE_SOCKS5 = socks.PROXY_TYPE_SOCKS5
PROXY_TYPE_HTTP = socks.PROXY_TYPE_HTTP


if platform.system() == "Windows":
            debug("Using Windows")
            debug("Setting Directory to Save Settings to: ")
            debug(str(SETTINGS_DIR))
elif platform.system() == "Linux":
            debug("Using Linux")
            debug("Setting Directory to Save Settings to: ")
            debug(str(SETTINGS_DIR))
elif platform.system() == "Darwin":
            debug("Using OS X")
            debug("Setting Directory to Save Settings to: ")
            debug(str(SETTINGS_DIR))

if reset_settings and os.path.exists(os.path.join(SETTINGS_DIR,"settings.mds")):
    "Deleting Settings File:" + str(os.path.join(SETTINGS_DIR,"settings.mds"))
    os.remove(os.path.join(SETTINGS_DIR,"settings.mds"))

''' Import All required Modules '''
from settings import    MailDropSettings, \
                        SettingsError, \
                        PROXY_AUTO, \
                        PROXY_MAN, \
                        PROXY_OFF
                        
import Counter

import MailThread

import settings
                        
from connector import ImapConnector                        
from downloader import ImapDownloader   
                    




